#!/usr/bin/python3
import os
import sys

args = sys.argv

if len(args) < 3:
    print("usage fduos-addr2line <kernel> <addresses>")
    exit()

kernel = args[1]
if not os.path.exists(kernel):
    print(f'kernel image {kernel} not found.')
    exit()

args.reverse()
args = args[:-2]
tools = [
    '/usr/bin/addr2line', 
    '/usr/bin/aarch64-linux-gnu-addr2line'
]
tool = None

# find addr2line
for t in tools:
    if os.path.exists(t):
        tool = t
        break

if tool is None:
    print("FATAL: cannot find addr2line");
    exit()

for arg in args:
    os.system(f'{tool} -f -a -p -e {kernel} 0x{arg}')
